import 'package:inmotion_pro/l10n/local.dart';
import 'package:inmotion_pro/pages/mine/user_info/controller.dart';
import 'package:inmotion_pro/pages/mine/view/avatar_view.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:lx_widgets_library/lx_widgets_library.dart';

import '../../others/custom_view/setting_items/settting_section.dart';

// 用户信息视图
class UserInfoView extends BaseGetView<UserInfoController> {
  UserInfoView({super.key});

  @override
  String get title => local.modify_user_info;

  @override
  Widget buildBody(BuildContext context) {
    return Material(
      color: Colors.black,
      child: Obx(() {
        final itemList = controller.state.itemList;
        return Column(
          children: [
            SizedBox(height: CONTENT_MARGIN * 3),
            GestureDetector(
              onTap: () {
                controller.clickAvatarOnTap();
              },
              child: Column(
                children: [
                  // 头像
                  Obx(
                    () => AvatarView(
                      avatarPath: controller.state.userInfo.value.avatar,
                      isLoggedIn: true,
                      size: 100.w,
                    ),
                  ),
                  SizedBox(height: CONTENT_MARGIN),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      LxText(local.edit),
                      SizedBox(width: CONTENT_MARGIN / 2),
                      Icon(
                        Icons.edit_note_sharp,
                        size: 18,
                        color: Colors.grey[400],
                      ),
                    ],
                  ),
                ],
              ),
            ),
            SizedBox(height: CONTENT_MARGIN * 2),
            Expanded(
              child: ListView.builder(
                itemCount: itemList.length,
                itemBuilder: (context, sectionIndex) {
                  final section = itemList[sectionIndex];
                  return SettingSection(
                    title: section.sectionType.name,
                    children: section.subItems,
                  );
                },
              ),
            ),
          ],
        );
      }),
    );
  }
}
